package com.fable.sgms.syslog.service.impl;

import com.fable.sgms.syslog.dao.entity.SysLog;
import com.fable.sgms.syslog.dao.entity.SysLogDetail;
import com.fable.sgms.syslog.mapper.SysLogDetailMapper;
import com.fable.sgms.syslog.mapper.SysLogMapper;
import com.fable.sgms.syslog.service.SysLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SysLogServiceImpl implements SysLogService {
    @Resource
    private SysLogMapper sysLogMapper;

    @Resource
    private SysLogDetailMapper sysLogDetailMapper;

    @Override
    public SysLog selectById(String id) {
        return sysLogMapper.selectByPrimaryKey(id);
    }


    @Override
    public PageInfo<SysLog> query(SysLog entity) {
        return PageHelper.startPage(entity.getPageNum(), entity.getPageSize()).doSelectPageInfo(() -> sysLogMapper.select(entity));
    }


    @Override
    public SysLog save(SysLog sysLog) {
        sysLogMapper.insert(sysLog);
        return sysLog;
    }

    @Override
    public void update(SysLog sysLog) {
        sysLogMapper.updateByPrimaryKey(sysLog);
    }

    @Override
    public void delete(String id) {
        sysLogMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteBatch(String[] ids) {
        sysLogMapper.deleteBatch(ids);
    }

    @Override
    public SysLogDetail selectLogDetail(String logId) {
        return sysLogDetailMapper.selectOne(SysLogDetail.builder().logId(logId).build());
    }

    @Override
    public void saveLogDetail(SysLogDetail sysLogDetail) {
        sysLogDetailMapper.insert(sysLogDetail);
    }
}
